#ifndef HISTORYMESSAGEWIDGET_H
#define HISTORYMESSAGEWIDGET_H

#include <QDialog>
#include <QWidget>
#include <QGridLayout>
#include <QIcon>
#include <QRadioButton>
#include <QLineEdit>
#include <QPushButton>
#include <QLabel>
#include <QDateTimeEdit>
#include <QScrollArea>
#include <QScrollBar>
#include <QStyleOption>
#include <QPainter>
#include <QFileDialog>

#include "model/data.h"
#include "model/datacenter.h"
#include "soundrecorder.h"

using model::Message;

//////////////////////////////////////////////
/// \brief 历史消息内容类
//////////////////////////////////////////////
class HistoryMessageItem: public QWidget{
    Q_OBJECT
public:
    HistoryMessageItem(const Message &msg);

    static HistoryMessageItem* makeHistoryMessageItem(const Message& msg);

    void paintEvent(QPaintEvent *) override; // 自定义类的样式需要重写此函数才能生效
};


//////////////////////////////////////////////
/// \brief        历史消息窗口
//////////////////////////////////////////////
class HistoryMessageWidget : public QDialog
{
    Q_OBJECT
public:
    HistoryMessageWidget(QWidget* parent = nullptr);
    void RadioBtnsSlots();

private:
    void initScrollArea();
    void addHistoryMessage(const Message& message);
    void clear();

private slots:
    void clickSearchBtnDone();

private:
    QGridLayout* m_layout = nullptr;

    QRadioButton* m_keySearchBtn = nullptr;
    QRadioButton* m_dateSearchBtn = nullptr;

    QLineEdit* m_searchEdit = nullptr;

    QLabel* m_startDateLabel = nullptr;
    QLabel* m_endDateLabel = nullptr;
    QDateTimeEdit* m_startTimeEdit = nullptr;
    QDateTimeEdit* m_endTimeEdit = nullptr;

    QPushButton* m_searchBtn = nullptr;

    QWidget* m_container = nullptr;         // 滚动区容器
};



//////////////////////////////////////////////
/// \brief          图片消息
//////////////////////////////////////////////
class ImageButton : public QPushButton{
    Q_OBJECT
public:
    ImageButton(const QString& fileID, const QByteArray& content);

private slots:
    void updateUI(const QString& fileID, const QByteArray& content);

private:
    QString m_fileID;
};


//////////////////////////////////////////////
/// \brief          文件消息
//////////////////////////////////////////////
class FileLabel: public QLabel{
    Q_OBJECT
public:
    FileLabel(const QString& fileID, const QString& fileName);

    void mousePressEvent(QMouseEvent* event) override;

private slots:
    void updateUI(const QString& fileID, const QByteArray& content);

private:
    QString m_fileID;
    QString m_fileName;
    QByteArray m_content;
    bool m_isLoad = false;
};


//////////////////////////////////////////////
/// \brief          语音消息
//////////////////////////////////////////////
class SpeechLabel: public QLabel{
    Q_OBJECT
public:
    SpeechLabel(const QString& fileID);

    void mousePressEvent(QMouseEvent* event) override;

private slots:
    void updateUI(const QString& fileID, const QByteArray& content);

private:
    bool m_isLoad = false;
    QString m_fileID;
    QByteArray m_content;
};

#endif // HISTORYMESSAGEWIDGET_H
